package avicit.bdp.dgs.mdm.rest;

import avicit.bdp.dgs.mdm.dto.MdataChangeDTO;
import avicit.bdp.dgs.mdm.service.MdataChangeService;
import avicit.platform6.core.rest.msg.QueryRespBean;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @金航数码科技有限责任公司
 * @作者：${tableInfo.classCreator}
 * @邮箱：${tableInfo.classMailbox}
 * @创建时间： 2023-12-06 11:02
 * @类说明：
 * @修改记录：
 */
@RestController
@Api(tags = "主数据变更明细")
@RequestMapping("/api/bdp/dgs/mdm/change")
public class MdataChangeRest {

    private static final Logger logger = LoggerFactory.getLogger(MdataChangeRest.class);

    @Autowired
    private MdataChangeService mdataChangeService;

    @ApiOperation(value = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "操作类型", name = "operType", dataType = "Int", paramType = "query"),
            @ApiImplicitParam(value = "当前页", name = "pageNo", dataType = "Int", paramType = "query"),
            @ApiImplicitParam(value = "每页大小", name = "pageSize", dataType = "Int", paramType = "query")
    })
    @GetMapping("/getPageList")
    public ResponseMsg<QueryRespBean<MdataChangeDTO>> getPageList(
            @RequestParam(required = false) Integer operType,
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "10") Integer pageSize) throws Exception {
        ResponseMsg<QueryRespBean<MdataChangeDTO>> responseMsg = new ResponseMsg<>();
        QueryRespBean<MdataChangeDTO> queryRespBean = mdataChangeService.getPageList(operType, pageNo, pageSize);
        responseMsg.setResponseBody(queryRespBean);
        return responseMsg;
    }

    @ApiOperation(value = "新增")
    @PostMapping("/save")
    public ResponseMsg<String> save(@RequestBody MdataChangeDTO dto) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(mdataChangeService.save(dto));
        return responseMsg;
    }

    @ApiOperation(value = "修改")
    @PutMapping("/update")
    public ResponseMsg<Boolean> update(@RequestBody MdataChangeDTO dto) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        mdataChangeService.update(dto);
        responseMsg.setResponseBody(true);
        return responseMsg;
    }

    @ApiOperation(value = "通过ID查询")
    @GetMapping("/queryById")
    public ResponseMsg<MdataChangeDTO> queryById(@ApiParam(value = "id", name = "id") @RequestParam String id) {
        ResponseMsg<MdataChangeDTO> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(mdataChangeService.queryById(id));
        return responseMsg;
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/deleteById")
    public ResponseMsg<Boolean> deleteById(@RequestParam String id) throws Exception{
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        mdataChangeService.deleteById(id);
        return responseMsg;
    }

}
